package com.example.bookstore.entity

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonView
import javax.persistence.Entity
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/10
 * Time: 18:39
 */
@Table
@Entity
class CartDetailEntity : BaseEntity {

    constructor() : super()
    constructor(cart: CartEntity, number: Int, book: BookEntity) : super() {
        this.cart = cart
        this.number = number
        this.book = book
    }

    @ManyToOne
//    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "cart_id", nullable = true, updatable = false)
    @JsonIgnoreProperties("cartDetails")
    lateinit var cart: CartEntity

    @JsonView(CartDetailView::class)
    var number: Int = 0

    @ManyToOne
//    @Fetch(FetchMode.JOIN)
    @JsonView(CartDetailView::class)
    @JoinColumn(name = "book_id", nullable = true, updatable = false)
    lateinit var book: BookEntity

    interface CartDetailView : BaseWithIdView
    interface CartDetailViewWithBook : CartDetailView, BookEntity.BookView
}